package com.unionfind;

/**
 * PS : path split
 * @Author: tgy
 * @Date: 2020-10-20 11:52
 */
public class UnionFind_QU_R_PS extends UnionFind_QU_R {

    public UnionFind_QU_R_PS(int capacity) {
        super(capacity);
    }

    @Override
    public int find(int v) {

        checkV(v);

        while (parents[v] != v) {

            int bv = parents[v];
            parents[v] = parents[bv];
            v = bv;
        }

        return v;
    }
}
